package com.a16.yuejian.yuejian.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.a16.yuejian.yuejian.R;
import com.a16.yuejian.yuejian.javabean.Comment;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by 王子恒 on 2017/11/3.
 */

public class CommentAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private List mDataList;
    private LayoutInflater mLayoutInflater;

    public CommentAdapter(Context mContext, List mDataList){
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.post_detail_commentcardview,parent,false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Comment entity = (Comment) mDataList.get(position);
        if (null == entity){
            return;
        }else {
            final ViewHolder viewHolder = (ViewHolder) holder;
            viewHolder.pt_detailcomment_username.setText(entity.getUsername());
            viewHolder.pt_detailcomment_time.setText(entity.getTime());
            viewHolder.pt_detailcomment_comment.setText(entity.getContent());
            Picasso.with(mContext).load("http://10.0.2.2:8080/neu_yuejian201/public/photo/"+entity.getPic()).into(viewHolder.pt_detailcomment_userpic);
        }

    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        ImageView pt_detailcomment_userpic;
        TextView pt_detailcomment_username,pt_detailcomment_time,pt_detailcomment_comment;
        LinearLayout pt_container;

        public ViewHolder(View itemView) {
            super(itemView);
            pt_detailcomment_username = (TextView) itemView.findViewById(R.id.pt_detailcomment_username);
            pt_detailcomment_userpic = (ImageView) itemView.findViewById(R.id.pt_detailcomment_userpic);
            pt_detailcomment_time = (TextView) itemView.findViewById(R.id.pt_detailcomment_time);
            pt_container= (LinearLayout)itemView.findViewById(R.id.pt_container);
            pt_detailcomment_comment = (TextView) itemView.findViewById(R.id.pt_detailcomment_comment);
        }
    }


}
